﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZhongheCms.Models;

namespace ZhongheCms.Controllers
{
    public class OnlineBuyController : Controller
    {
        //
        // GET: /OnlineBuy/

        public ActionResult Index(int id = 0, string m = "", string f = "", string p = "", string fid = "")
        {
            ViewBag.m = m;
            ViewBag.f = f;
            ViewBag.p = p;
            ViewBag.fid = fid;
           
            if (GswTblUser.CurrentUser == null)
                return RedirectToAction("Login", "Account");
            GswTblUser.CurrentUser.ModuleName = m;
            GswTblUser.CurrentUser.FuncName = f;
            var qry = GswTblBuyList.Fetch("where CustomerId="+GswTblUser.CurrentUser.CustomerId+" order by BuyDate desc");

            return View(qry);
        }

        public ActionResult Delete(int id = 0, string m = "", string f = "", string p = "", string fid = "")
        {
            ViewBag.m = m;
            ViewBag.f = f;
            ViewBag.p = p;
            ViewBag.fid = fid;

            if (GswTblUser.CurrentUser == null)
                return RedirectToAction("Login", "Account");
            GswTblBuyList.Delete(id);
            GswTblUser.CurrentUser.ModuleName = m;
            GswTblUser.CurrentUser.FuncName = f;
            var qry = GswTblBuyList.Fetch("where CustomerId=" + GswTblUser.CurrentUser.CustomerId + " order by BuyDate desc");

            return View("Index",qry);
        }

    }
}
